﻿using db_manage.dll.manage;
using db_manage.model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace db_manage.page
{
    public partial class form_bak_sub : Form
    {
        private db_config_bak_sub db_config_bak_sub { get; set; }

        public form_bak_sub(db_config_bak_sub db_config_bak_sub)
        {
            InitializeComponent();
            this.db_config_bak_sub = db_config_bak_sub;
            config_get();
        }

        /// <summary>
        /// 获取配置
        /// </summary>
        private void config_get()
        {
            dt_start.Value = db_config_bak_sub.time_start;
            dt_end.Value = db_config_bak_sub.time_end;
            tb_interval_full.Text = db_config_bak_sub.interval_full.ToString();
            tb_interval_diff.Text = db_config_bak_sub.interval_diff.ToString();
            cb_old_diff_del.Checked = db_config_bak_sub.bak_diff_del;
            cb_old_full_del.Checked = db_config_bak_sub.bak_full_del;
            tb_dir_bak.Text = db_config_bak_sub.dir_bak;
            tb_dir_username.Text = db_config_bak_sub.dir_username;
            tb_dir_pwd.Text = db_config_bak_sub.dir_pwd;
        }

        /// <summary>
        /// 设置配置
        /// </summary>
        private void config_set()
        {
            db_config_bak_sub.time_start = dt_start.Value;
            db_config_bak_sub.time_end = dt_end.Value;
            db_config_bak_sub.interval_full = Convert.ToInt32(tb_interval_full.Text);
            db_config_bak_sub.interval_diff = Convert.ToInt32(tb_interval_diff.Text);
            db_config_bak_sub.bak_diff_del = cb_old_diff_del.Checked;
            db_config_bak_sub.bak_full_del = cb_old_full_del.Checked;
            db_config_bak_sub.dir_bak = tb_dir_bak.Text;
            db_config_bak_sub.dir_username = tb_dir_username.Text;
            db_config_bak_sub.dir_pwd = tb_dir_pwd.Text;
        }

        /// <summary>
        /// 备份目录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_dir_bak_Click(object sender, EventArgs e)
        {
            //展示对话框
            fbd_dir_bak.ShowDialog();

            ////获得在打开的对话框中选中的路径
            string path = fbd_dir_bak.SelectedPath;

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            tb_dir_bak.Text = path;
        }

        /// <summary>
        /// 保存配置
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void bt_save_Click(object sender, EventArgs e)
        {
            config_set();
            manage.db_manage_config = manage.db_manage_config;
            MessageBox.Show("操作完成");
        }
    }
}
